package com.xinli.business.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xinli.business.domain.TGuide;
import com.xinli.business.service.ITGuideService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xinli.common.annotation.Log;
import com.xinli.common.core.controller.BaseController;
import com.xinli.common.core.domain.AjaxResult;
import com.xinli.common.enums.BusinessType;
import com.xinli.common.utils.poi.ExcelUtil;
import com.xinli.common.core.page.TableDataInfo;

/**
 * 咨询指南Controller
 *
 * @author ruoyi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/business/guide")
public class TGuideController extends BaseController
{
    @Autowired
    private ITGuideService tGuideService;

    /**
     * 查询咨询指南列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TGuide tGuide)
    {
        startPage();
        List<TGuide> list = tGuideService.selectTGuideList(tGuide);
        return getDataTable(list);
    }

    /**
     * 导出咨询指南列表
     */
    @Log(title = "咨询指南", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TGuide tGuide)
    {
        List<TGuide> list = tGuideService.selectTGuideList(tGuide);
        ExcelUtil<TGuide> util = new ExcelUtil<TGuide>(TGuide.class);
        util.exportExcel(response, list, "咨询指南数据");
    }

    /**
     * 获取咨询指南详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(tGuideService.selectTGuideById(id));
    }

    /**
     * 新增咨询指南
     */
    @Log(title = "咨询指南", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TGuide tGuide)
    {
        return toAjax(tGuideService.save(tGuide));
    }

    /**
     * 修改咨询指南
     */
    @Log(title = "咨询指南", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TGuide tGuide)
    {
        return toAjax(tGuideService.updateById(tGuide));
    }

    /**
     * 删除咨询指南
     */
    @Log(title = "咨询指南", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tGuideService.removeByIds(Arrays.asList(ids)));
    }
}
